package com.happle.gcmclient.obj;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.happle.gcmclient.config.Constants;

@SuppressWarnings("serial")
public class MessageObj implements Parcelable {

	private String _msg_id_local = "";
	private String _wave_id = "";
	private boolean _is_owner = false;
	private String _message = "";
	private String _lng_id = "";
	// private DateFormat[] _datetime;
	private Date _datetime = new Date();
	private boolean _msg_status = false;
	private int _msg_order = 0;
	private boolean _is_sent = false;
    private boolean _is_new = false;

	public MessageObj() {
		super();
	}

	public MessageObj(String _wave_id, String _message) {
		super();
		this._wave_id = _wave_id;
		this._message = _message;
		this._datetime = new Date();
		this._msg_id_local = null;
		this._is_owner = false;
		this._lng_id = Constants.LANGUAGE_ID;
		this._msg_status = true;
		this._msg_order = 0;
		this._is_sent = false;
        this._is_new = false;
	}

	public MessageObj(String msg_id_local, String wave_id, boolean is_owner,
			String message, String lng_id, boolean msg_status, int msg_order,
			boolean is_sent) {

		super();
		this._msg_id_local = msg_id_local;
		this._wave_id = wave_id;
		this._is_owner = is_owner;
		this._message = message;
		this._lng_id = lng_id;
		this._datetime = new Date();
		this._msg_status = msg_status;
		this._msg_order = msg_order;
		this._is_sent = is_sent;
        this._is_new = false;
	}

	public MessageObj(String msg_id_local, String wave_id, boolean is_owner,
			String message, String lng_id, Date datetime, boolean msg_status,
			int msg_order, boolean is_sent) {

		this._msg_id_local = msg_id_local;
		this._wave_id = wave_id;
		this._is_owner = is_owner;
		this._message = message;
		this._lng_id = lng_id;
		this._datetime = datetime;
		this._msg_status = msg_status;
		this._msg_order = msg_order;
		this._is_sent = is_sent;
        this._is_new = false;
	}

	public MessageObj(String msg_id_local, String wave_id, boolean is_owner,
			String message, String lng_id, Date datetime, boolean msg_status) {

		this._msg_id_local = msg_id_local;
		this._wave_id = wave_id;
		this._is_owner = is_owner;
		this._message = message;
		this._lng_id = lng_id;
		this._datetime = datetime;
		this._msg_status = msg_status;
		this._msg_order = 0;
		this._is_sent = true;
        this._is_new = false;
	}

    public MessageObj(String msg_id_local, String wave_id, boolean is_owner,
                      String message, String lng_id, Date datetime, boolean msg_status,
                      int msg_order, boolean is_sent, boolean is_new) {

        this._msg_id_local = msg_id_local;
        this._wave_id = wave_id;
        this._is_owner = is_owner;
        this._message = message;
        this._lng_id = lng_id;
        this._datetime = datetime;
        this._msg_status = msg_status;
        this._msg_order = msg_order;
        this._is_sent = is_sent;
        this._is_new = is_new;
    }

	// in case the _date would be datetime format
	public String getDateTime(String sDate) {
		String datetime_str = null;
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm");
		Date convertedDate = new Date();
		try {
			convertedDate = formatter.parse(sDate);
			datetime_str = String.valueOf(convertedDate);
		} catch (Exception e) {
			Log.d("NoteObj date format exception: ", e.getMessage());
		}
		return datetime_str;
	}

	public String convertNowToFullDateString() {
		SimpleDateFormat dateformat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		// dateformat.setTimeZone(TimeZone.getTimeZone("GMT"));

		// Calendar calendar =
		// Calendar.getInstance(TimeZone.getTimeZone("GMT"));
		// return dateformat.format(calendar.getTime());
		return dateformat.format(new Date());
	}

	// get set
	public String get_msg_id_local() {
		return _msg_id_local;
	}

	public void set_msg_id_local(String _msg_id_local) {
		this._msg_id_local = _msg_id_local;
	}

	public String get_wave_id() {
		return _wave_id;
	}

	public void set_wave_id(String _wave_id) {
		this._wave_id = _wave_id;
	}

	public boolean is_is_owner() {
		return _is_owner;
	}

	public void set_is_owner(boolean _is_owner) {
		this._is_owner = _is_owner;
	}

	public String get_message() {
		return _message;
	}

	public void set_message(String _message) {
		this._message = _message;
	}

	public String get_lng_id() {
		return _lng_id;
	}

	public void set_lng_id(String _lng_id) {
		this._lng_id = _lng_id;
	}

	public Date get_datetime() {
		return _datetime;
	}

	public void set_datetime(Date _datetime) {
		this._datetime = _datetime;
	}

	public boolean is_msg_status() {
		return _msg_status;
	}

	public void set_msg_status(boolean _msg_status) {
		this._msg_status = _msg_status;
	}

	public int get_msg_order() {
		return _msg_order;
	}

	public void set_msg_order(int _msg_order) {
		this._msg_order = _msg_order;
	}

	public boolean is_is_sent() {
		return _is_sent;
	}

	public void set_is_sent(boolean _is_sent) {
		this._is_sent = _is_sent;
	}

    public boolean is_is_new() {
        return _is_new;
    }

    public void set_is_new(boolean _is_new) {
        this._is_new = _is_new;
    }

	// end get set
	// Parcelling part
	@Override
	public int describeContents() {
		return 0;
	}

	@SuppressWarnings("deprecation")
	public MessageObj(Parcel in) {
		_msg_id_local = in.readString();
		_wave_id = in.readString();
		_is_owner = in.readByte() != 0;
		_message = in.readString();
		_lng_id = in.readString();
		_datetime = new Date(in.readLong());
		_msg_status = in.readByte() != 0;
		_msg_order = in.readInt();
		_is_sent = in.readByte() != 0;
	}

	@Override
	public void writeToParcel(Parcel in, int flags) {
		in.writeString(_msg_id_local);
		in.writeString(_wave_id);
		in.writeByte((byte) (_is_owner ? 1 : 0));
		in.writeString(_message);
		in.writeString(_lng_id);
		in.writeLong(_datetime.getTime());
		in.writeByte((byte)(_msg_status ? 1 : 0));
		in.writeInt(_msg_order);
		in.writeByte((byte)(_is_sent ? 1 : 0));
	}

	public static final Parcelable.Creator<MessageObj> CREATOR = new Parcelable.Creator<MessageObj>() {
		@Override
		public MessageObj createFromParcel(Parcel parcel) {
			return new MessageObj(parcel);
		}

		@Override
		public MessageObj[] newArray(int size) {
			return new MessageObj[size];
		}
	};

	public String toString() {

		return new StringBuilder().append("msg id local: ")
				.append(_msg_id_local).append("_wave_id: ").append(_wave_id)
				.append("_is_owner: ").append(_is_owner).append("_message: ")
				.append(_message).append("_datetime: ").append(_datetime)
				.append("_msg_status: ").append(_msg_status)
				.append("_msg_order: ").append(_msg_order).append("_is_sent: ")
				.append(_is_sent).toString();
	}
}
